package mapEditor.obj;

import debug.*;

import mapEditor.svg.SVGDOMTree;
import mapEditor.utils.Util;

import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPanel;

import org.w3c.dom.svg.SVGGElement;


// DOC: http://www.w3.org/TR/SVG11/struct.html#Groups
// DOC: http://www.zvon.org/xxl/svgReference/Output/el_g.html
public class GroupObject extends DrawObject
{ //protected static final boolean USE_AnimatedLength=false; // OVERRIDE (to make updateSVGElement work)

  public GroupObject(SVGDOMTree domTree)
  { super(domTree,domTree.appendSVGGElement());
  }
  
  public GroupObject(SVGDOMTree domTree,SVGGElement svgElement)
  { super(domTree,svgElement);
	decodeSVG(svgElement);
  }
  
  public void decodeSVG(SVGGElement svgElement)
  { Debug.TRACE("GroupObject.decodeSVG: svgElement="+svgElement);
    this.setIdent(svgElement.getAttribute("id"));
  }
  
  protected void directUpdateSVGElement()
  {
//	SVGGElement group=(SVGGElement)svgElement;
  }

  
  // ****************************************************************
  // *** INNER CLASS: EditGeneralPanel
  // ****************************************************************
  public JPanel getEditGeneralPanel(String title)
  { return(new EditGeneralPanel(title)); }
  private class EditGeneralPanel extends JPanel
  { static final long serialVersionUID=0; // AD'HOC
    private JTextField identField;
    private JButton strokeButton;
    
    public void paint(Graphics g)
    { Debug.TRACE("GroupObject.EditGeneralPanel.paint: ");
      identField.setText(getIdent());
      strokeButton.setBackground(stroke.getColor());
  	  super.paint(g);  
    }
  	
    public EditGeneralPanel(String title)
    { setBorder(Util.getTitleBorder(title));
      setPreferredSize(new Dimension(350,50+20));
      setLayout(new GridLayout(2,2));
      add(new JLabel("Ident:"));
      identField=new JTextField(getIdent());
      identField.addActionListener(new ActionListener()
      { public void actionPerformed(ActionEvent e)
        { setIdent(identField.getText()); }
      });
      add(identField);
      strokeButton=addEditStrokeButton(this,true);
    }
  }    

}
